<?php

/**
 * 服务管理程序
*/

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

$act = $_REQUEST["act"];
$op = $_REQUEST["op"];
if($op == "save")
{
	$brief = isset($_REQUEST["brief"]) ? trim($_REQUEST["brief"]) : '';
	$service_desc = isset($_REQUEST["service_desc"]) ? trim($_REQUEST["service_desc"]) : '';
	$keywords = isset($_REQUEST["keywords"]) ? trim($_REQUEST["keywords"]) : '';
	$timelist = $_REQUEST["timelist"];
	$number   = $_REQUEST["number"];
	$urgency  = $_REQUEST["urgency"];
	$price    = $_REQUEST["price"];
	$minletter = $_REQUEST["minletter"];
	$maxletter = $_REQUEST["maxletter"];
	$maxsize   = intval($_REQUEST['maxsize']);
	$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
	if($act == "essay" || $act == "chenshu") {
		$price = @serialize($price);
		$minletter = @serialize($minletter);
		$maxletter = @serialize($maxletter);
	}
	
	if($act == "multiple" || $act == "quiz") {
		$timelist = @serialize($timelist);
		$number = @serialize($number);
	}
	
	$data = array(
		'brief' => $brief,
		'urgency' => $urgency,
		'price' => $price,
		'minletter' => $minletter,
		'maxletter' => $maxletter,
		'maxsize'   => $maxsize,
		'timelist'   => $timelist,
		'number'   => $number,
		'keywords'   => $keywords,
		'service_desc' => $service_desc,
	);
	
	$db->autoExecute($ecs->table("service"), $data, "UPDATE", "id='{$id}'");
	sys_msg("服务更新成功！");
}
    $smarty->assign('ur_here', new_ur_here($act));
    $smarty->assign('service', get_service_info($act));
$smarty->display($act.".htm");

function new_ur_here($act)
{
	$name = "";
	switch($act)
	{
		case "essay":
			$name = "Essay修改";
			break;
		case "resume":
			$name = "简历推荐信";
			break;
		case "all":
			$name = "全套申请";
			break;
		case "multiple":
			$name = "申请综合咨询";
			break;
		case "quiz":
			$name = "模拟面试";
			break;
		case "chenshu":
			$name = "个人陈述修改";
			break;
	}
	return "服务管理 - ".$name;
}

function get_service_info($act)
{
	$sql = "SELECT * FROM " . $GLOBALS['ecs']->table("service") . " WHERE type = '$act'";
	$info = $GLOBALS['db']->getRow($sql);
	if($act == "essay" || $act == "chenshu")
	{
		$info["price"] = @unserialize($info["price"]);
		$info["minletter"] = @unserialize($info["minletter"]);
		$info["maxletter"] = @unserialize($info["maxletter"]);
	}
	
	if($act == "multiple" || $act == "quiz") {
		$info["timelist"] = @unserialize($info["timelist"]);
		$info["number"] = @unserialize($info["number"]);
	}
	
	return $info;
}
?>